package algorithm.leetcode.I201to400;

import java.util.Arrays;

/**
 * 反转字符串,要求原地修改
 */

public class Q344 {
    public void reverseString(char[] s) {
        int low = 0, high = s.length-1;

        while (low < high) {
            swapChar(s, low, high);
            low++;
            high--;
        }
    }

    public static void swapChar(char[] s, int left, int right) {
        s[left] ^= s[right];
        s[right] ^= s[left];
        s[left] ^= s[right];
    }


    public static void main(String[] args) {
        Q344 q344 = new Q344();
        char[] chars = {'h', 'e', 'l', 'l', 'o'};
        q344.reverseString(chars);
        System.out.println(Arrays.toString(chars));
    }
}
